using System;
using System.Collections.Generic;
using OpenQA.Selenium;
using System.Linq;

namespace YatFram.Browser.Selenium
{
    public class SeleniumContainerElement : SeleniumHtmlElement, IContainerElement
    {
        public SeleniumContainerElement(Func<IWebElement> element) : base(element())
        {
        }

        public bool Exists
        {
            get { throw new NotImplementedException("Exists"); }
        }

//        public IContainerElement Find(string cssSelector)
//        {
//            return new SeleniumContainerElement(() => element.FindElement(cssSelector));
//        }
        public IEnumerable<IContainerElement> Find(CssSelector.CssSelectors selector)
        {
            return
                element.FindElements(SeleniumConstraints.ToSeleniumConstraint(selector)).Select(
                    e => (IContainerElement) new SeleniumContainerElement(() => e));
        }

        public InputElement FindTextBox(string cssSelector)
        {
            return new SeleniumTextBox(element.FindElement(cssSelector));
        }

        public ISingleOption FindSelect(string cssSelector)
        {
            return new SeleniumRadioBox(element.FindElement(cssSelector).FindElements(By.TagName("option")));
        }

        public ISingleOption FindRadio(string name)
        {
            return new SeleniumRadioBox(element.FindElements(By.Name(name)));
        }

        public IMultipleOptions FindCheckbox(string name)
        {
            return new SeleniumMultipleOptions(element.FindElements(By.Name(name)));
        }
    }
}